import { defineStore } from "pinia";

export const useUserStore = defineStore('user',{
  state(){
    return {
      userid:localStorage.getItem('userid')||'',
      tel:localStorage.getItem('tel')||''
    }
  },
  actions:{
    setUserId(payload:string){
      this.userid = payload;
      // 当获取用户id，把他存到本地存储  - 数据的持久化
      localStorage.setItem('userid',payload)
    },
    setTel(payload:string){
      this.tel = payload;
      // 当获取用户tel，把他存到本地存储  - 数据的持久化
      localStorage.setItem('tel',payload)
    },
    logout(){
      this.userid = '';
      this.tel = '';
      localStorage.removeItem('userid')
      localStorage.removeItem('tel')
      localStorage.removeItem('token')
    }
  }
})